package os_listener;


public class OS_Listener implements Runnable
{
	//will be used for keeping the massages from OS
	String massage;
	//flags for updating the state of the service
	Boolean stop;
	Boolean pause;
	
	/**
	 * A handle to the unique OS_Listener instance.
	 */
	static private OS_Listener instance = null;
	//for the singleton
	private static Object someObject=new Object();
	
	private OS_Listener() 
	{
		massage=null;
		stop=true;
		pause=false;
	}
	
	 /**
	 * @return The unique instance of this class.
	 */
	static public OS_Listener getInstance() 
	{
		if(null == instance) 
		{
			//to insure that the time slice doesn't cause the creation of 2 instances
			synchronized (someObject) 
			{
				if (null == instance)
					instance = new OS_Listener();
			}
		}
	    return instance;
	}
	
	public void run() 
	{
		boolean printed_once = false;
		while(stop==false)
		{
			if(!printed_once)
			{
				System.out.println("now the service will spy on the " +
				"OS until it will discover a change(the flags of the state will be checked)");
				try 
				{
					Thread.sleep(2000);
				}	 
				catch (InterruptedException e) {}
				System.out.println("a change was discovered, sending the massage to processing");
				processMassage(massage);
				printed_once = true;
			}
		}
		System.out.println("the service stopped - the end of this thread");
	}

	private void processMassage(String massage2) 
	{
		System.out.println("in case the massage was adding a new file, " +
				"we will send the massage to the tag manager " +
				"program for automatic tagging using socket with our own protocol");
		
		System.out.println("connecting to the server and sending the " +
							"massage to it with protocol http");
	
		System.out.println("waiting for a massage from the server " +
						"(in order to know if the action was successfull)");
	}
	
	public Boolean getStop() 
	{
		return stop;
	}

	public void setStop(Boolean stop) 
	{
		this.stop = stop;
	}

	public Boolean getPause() 
	{
		return pause;
	}

	public void setPause(Boolean pause) 
	{
		this.pause = pause;
	}
	
	
	
}
